/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package baseObjects;

/**
 *
 * @author yoav
 */
public class Symbol {

    private Character regular = null;
    private Character shift = null;
    private Character alt = null;
    private Character ctrl = null;
    private double probobility = 0;

    public Symbol(Character reg, Character tshift) {
        regular = reg;
        shift = tshift;
    }
        public Symbol(Character reg, Character tshift,Character talt,Character tctrl) {
        regular = reg;
        shift = tshift;
        alt=talt;
        ctrl=tctrl;
    }
    
    
    public Symbol(Symbol other){
        this.regular = other.regular;
        this.shift = other.shift;
        this.ctrl = other.ctrl;
        this.alt = other.alt;
        this.probobility = other.probobility;
    }

    public void setProbobility(double probobility) {
        this.probobility = probobility;
    }

    public double getProbobility() {
        return probobility;
    }

    public Symbol(Character reg) {
        regular = reg;
    }

    public Character getAlt() {
        return alt;
    }

    public Character getCtrl() {
        return ctrl;
    }

    public Character getRegular() {
        return regular;
    }

    public Character getShift() {
        return shift;
    }

    public void setAlt(Character alt) {
        this.alt = alt;
    }

    public void setCtrl(Character ctrl) {
        this.ctrl = ctrl;
    }

    public void setRegular(Character regular) {
        this.regular = regular;
    }

    public void setShift(Character shift) {
        this.shift = shift;
    }

    @Override
    public boolean equals(Object obj) {
       
        
        if (obj == null) {
            return false;
        }
        if (obj instanceof Character) {
            return regular.equals(obj) || 
                    (shift!=null?shift.equals(obj):false )  ||
                    (alt!=null?alt.equals(obj):false) ||
                    (ctrl!=null?ctrl.equals(obj):false);
        }
        if (obj instanceof Symbol) {
            Symbol other = (Symbol) obj;
            return regular.equals(other.regular) &&
                    (shift != null ? shift.equals(other.shift) : (other.shift != null ? false : true)) &&
                    (alt != null ? alt.equals(other.alt) : (other.alt != null ? false : true)) &&
                    (ctrl != null ? ctrl.equals(other.ctrl) : (other.ctrl != null ? false : true));
        }        
        return false;
    }

    @Override
    public int hashCode() {
        int hash =0;
        
        hash = Character.getNumericValue(this.regular);
        hash += (this.shift != null?Character.getNumericValue(this.shift):0);
        hash += (this.ctrl != null?Character.getNumericValue(this.ctrl):0);
        hash += (this.alt != null?Character.getNumericValue(this.alt):0);
        return hash;
    }


    
    public void updateProbability(double amount){
        this.probobility += amount;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[ "+(regular!=null?regular:""));
        sb.append(", "+(shift!=null?shift:""));
        sb.append(", "+(alt!=null?alt:""));
        sb.append(", "+(ctrl!=null?ctrl:""));
        sb.append(",  "+probobility+"]");

        return sb.toString();
    }

    public String toXML(){


      return null;
    }



}
